gnuplot pdfcairo 匹配乳胶字体大小

lul*_*xvi 6 latex gnuplot cairo

我使用带有 pdfcairo 终端的 gnuplot 5.0 绘制 pdf 图,然后使用 Latex 将该图插入到 pdf 文件中。然而,我发现gunplot中的字体大小与latex中的字体大小不同,尽管我将它们设置为相同。

为了使gnuplot和latex中的字体大小一致,我必须将gnuplot中的字体比例设置为0.75,如以下代码所示。

gnuplot 代码:用蓝色绘制“A”(Helvetica,大小 12,字体比例 0.75)。

set terminal pdfcairo font 'Helvetica,12' size 1cm,1cm fontscale 0.75
set output 'test0.pdf'
set xrange [-1:1]
set yrange [-1:1]
unset xtics
unset ytics
unset border
set label 'A' at 0,0 textcolor 'blue'
p 1/0 notitle
Run Code Online (Sandbox Code Playgroud)

Latex 代码:按原始大小插入前一个数字,并在前一个“A”旁边写一个黑色“A”(Helvetica,尺寸 12)。

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{helvet}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {\includegraphics{test0.pdf}};
\node at (0.3, -0.025) {\textsf{A}};
\end{tikzpicture}
\end{document}
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看最终的 pdf 文件。现在我们可以看到,在 gnuplot 设置“fontscale 0.75”下,这两个“A”的大小完全相同。我不明白为什么在 gnuplot 中应该使用“fontscale 0.75”,而不是“fontscale 1”?这是开罗的问题吗?有没有什么优雅的方法来处理这个字体大小问题?


简短回答:gnuplot 使用 72dpi,而 cairo 使用 96dpi。(96/72=4/3)

注意:出于同样的原因,如果使用 pngcairo,也应该使用 'fontscale 0.75' 来获得正确的字体大小。

替代解决方案:cairolatex。@用户8153

ewc*_*wcz 6

我认为这可能是由于开罗渲染造成的。为了设置字体大小,Gnuplot 使用提供的大小调用函数pango_font_description_set_size ,在您的情况下为 12。然而,这随后被转换为开罗单位:

字体大小(以磅为单位),按 PANGO_SCALE 缩放。(即,大小值 10 * PANGO_SCALE 是 10 点字体。点和设备单位之间的转换系数取决于系统配置和输出设备。对于屏幕显示,逻辑 DPI 很常见,在这种情况下10 点字体对应于 10 * (96 / 72) = 13.3 像素字体。

此外,从函数的文档来看pango_cairo_font_map_set_resolution

/**
 * pango_cairo_font_map_set_resolution:
 * @fontmap: a #PangoCairoFontMap
 * @dpi: the resolution in "dots per inch". (Physical inches aren't actually
 *   involved; the terminology is conventional.)
 *
 * Sets the resolution for the fontmap. This is a scale factor between
 * points specified in a #PangoFontDescription and Cairo units. The
 * default value is 96, meaning that a 10 point font will be 13
 * units high. (10 * 96. / 72. = 13.3).
 *
 * Since: 1.10
 **/
Run Code Online (Sandbox Code Playgroud)

总而言之,似乎提供的大小是为了渲染的目的而乘以它96/72 = 4/3有效地产生大小为 16 而不是 12 的字体。0.75然后您应用的缩放因子将恢复它。