r - 使用 gdtools::font_family_exists 检测系统字体的问题
问题描述
ggiraph
我想通过将字体更改为“DejaVu Sans Condensed”来绘制一个交互式 html 图。这种特殊字体与我将其放入 css 时的交互式工具提示效果很好girafe
,但不能作为 html 绘图本身中文本元素的通用字体。让我们尝试一个例子。首先,使用 ggplot2 一切正常:
library(tidyverse)
library(ggiraph)
windowsFonts(sans = windowsFont("DejaVu Sans Condensed"))
z <- ggplot(data = iris,
mapping = aes(x = Sepal.Length, y = Petal.Width)) +
geom_point() +
ggtitle("Title with special characters ♀♂") +
xlab("Sepal.Length ♀♂") + ylab("Miles per Gallon ♀♂" ) +
theme_minimal(base_family = "sans", base_size = 18)
z
我们可以看到 DejaVu Sans Condensed 字体起作用了,因为标题中的男性和女性符号与字母一样粗体。但是使用girafe
,符号显得更薄,因为字体不起作用/回到 Arial :
girafe(ggobj = z, fonts = list(sans = "DejaVu Sans Condensed"))
问题可能来自用于管理字体的gdtools
包ggiraph
,因为它找不到 DejaVu Sans Condensed :
gdtools::font_family_exists("DejaVu Sans Condensed")
# [1] FALSE
但是,如果我们使用gdtools::sys_fonts
,我们可以找到 DejaVu Sans Condensed,但字体系列名称不完整:
gdtools::sys_fonts() %>% filter(str_detect(name, "DejaVuSansCondensed")) %>% select(3:5)
# A tibble: 4 x 3
# name family style
# DejaVuSansCondensed-Bold DejaVu Sans Condensed Bold
# DejaVuSansCondensed-BoldOblique DejaVu Sans Condensed Bold Oblique
# DejaVuSansCondensed-Oblique DejaVu Sans Condensed Oblique
# DejaVuSansCondensed DejaVu Sans Condensed
“DejaVu Sans Condensed”存在,但“family”名称只是“Deja Vu Sans”,而“Condensed”部分转到“style”(在我电脑中这种字体的资料中,使用 Windows,字体系列名称是“DejaVu Sans Condensed”)。
是系统字体检测算法有问题吗?或者它是一种正常的行为,然后在哪里指定 Condensed 样式来使用它ggiraph
?
谢谢,
解决方案
推荐阅读
- python - Pandas 使用“包含”逻辑基于列表删除行
- html - 画布元素的媒体查询
- java - 注意:myline.java 使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息
- python-3.6 - 调用 logging.basicConfig 时重复日志
- jvm - 使用wildfly在项目中自动增加堆空间(不在standalone.conf中)
- python - 在简单的数学运算中更改数字顺序会产生不同的结果?
- android - 如何在 Android Compose 中使用 otf 类型的字体文件?
- image-processing - 是否有一个点的属性,在 2D 空间中的每个位置都不同?
- php - 如何将 PHP 显示为文本代码,而不是可执行文件?
- javascript - 找不到模块:无法解析“firebase”