react-pdf 中的样式显示异常行为

Kno*_*ker 2 css text-styling reactjs react-pdf

我正在尝试在 react-pdf 中使用斜体样式。

一切正常,直到我使用font-style: italic;.

在 react-pdf 中是否有另一种方式将文本样式设置为斜体?

const Italic = styled.Text`
  font-size: 12px;
  lineheight: 20px;
  text-align: left;
  font-family: "Roboto Condensed";
  letter-spacing: 0.5px;
  font-style: italic;//problem is with this line
  font-weight:400;
`;
Run Code Online (Sandbox Code Playgroud)

它给了我错误:

未捕获(承诺)错误:无法解析未定义的字体,fontWeight 400

小智 6

当您注册字体时,您需要确保为每个fontStyle要使用的字体包含一个变体。例如:

Font.register({
  family: 'Roboto',
  fonts: [
    { src: '<path-to-normal-font-variant>' },
    { src: '<path-to-italic-font-variant>', fontStyle: 'italic' },
    ...
  ]
});
Run Code Online (Sandbox Code Playgroud)