@@ -98,7 +98,6 @@ list_fonts <- function(gg) {
9898 list_layers_fonts(gg ),
9999 list_theme_fonts(gg )
100100 )
101- browser()
102101 fonts_families <- sort(unique(fonts_families ))
103102 fonts_families %|| % character ()
104103}
@@ -150,14 +149,30 @@ list_layers_fonts <- function(gg) {
150149}
151150
152151extract_family_names_regex <- function (lines ) {
153- # Pattern pour capturer le contenu entre quotes après font-family:
154- pattern <- " font-family:\\ s*['\" ]([^'\" ]+)['\" ]"
155- matches <- regmatches(lines , regexpr(pattern , lines , perl = TRUE ))
152+ # one single line
153+ css_text <- paste(lines , collapse = " \n " )
156154
157- # Extraire seulement le nom de la police (groupe capturé)
158- font_names <- gsub(" font-family:\\ s*['\" ]([^'\" ]+)['\" ]" , " \\ 1" , matches , perl = TRUE )
155+ # Pattern for @font-face
156+ fontface_pattern <- " @font-face\\ s*\\ {[^}]+\\ }"
157+ fontface_blocks <- regmatches(css_text , gregexpr(fontface_pattern , css_text , perl = TRUE ))[[1 ]]
159158
160- return (font_names )
159+ if (length(fontface_blocks ) == 0 ) {
160+ return (character ())
161+ }
162+
163+ # Pattern to extract family in @font-face blocks
164+ family_pattern <- " font-family:\\ s*['\" ]([^'\" ]+)['\" ]"
165+
166+ font_names <- character ()
167+ for (block in fontface_blocks ) {
168+ matches <- regmatches(block , regexpr(family_pattern , block , perl = TRUE ))
169+ if (length(matches ) > 0 ) {
170+ family_name <- gsub(family_pattern , " \\ 1" , matches , perl = TRUE )
171+ font_names <- c(font_names , family_name )
172+ }
173+ }
174+
175+ return (sort(unique(font_names )))
161176}
162177
163178htmldep_css_files <- function (dep ) {
0 commit comments