代码之家  ›  专栏  ›  技术社区  ›  tomw

当使用ggplot和ggtext渲染时,Inter不会以斜体显示

  •  0
  • tomw  · 技术社区  · 11 月前

    国际米兰有 italic specimens on Google Fonts ,但你下载的国际米兰 showtext::font_add_google() 不会呈现为斜体。

    举个例子

    library(tidyverse)
    library(showtext)
    library(ggtext)
    
    font_add_google("Inter")
    font_add_google("Roboto")
    
    t0 <- tibble(
      x = 1,
      y = 4:1,
      lab = c(
        "This is Roboto",
        "<i>This is Roboto</i>",
        "This is Inter",
        "<i>This is Inter</i>"
        )
      )
    
    showtext_auto()
    
    t0 %>% 
      ggplot(
      aes(
        x, y, label = lab
        )
      ) +
      geom_richtext(
        fill = "grey95",
        family = "Roboto",
        size = 10,
        label.color = NA,
        data = t0 %>% 
          filter(
            lab %>% 
              str_detect("Roboto")
          )
      ) +
      geom_richtext(
        fill = "grey95",
        family = "Inter",
        size = 10,
        label.color = NA,
        data = t0 %>% 
          filter(
            lab %>% 
              str_detect("Inter")
          )
      ) 
    

    enter image description here

    正如你所看到的,Roboto用斜体渲染,但国际米兰没有。

    1 回复  |  直到 11 月前
        1
  •  1
  •   nrennie    11 月前

    尝试更改 font_add_google("Inter") font_add_google("Inter", db_cache = FALSE) .这强制使用官方API下载字体,而不是缓存版本,而且它更为最新。(斜体版本可能比其他版本添加得更晚)。

    plot

    推荐文章