![桥接贝塞尔曲线节点文本粗细](https://linux22.com/image/430540/%E6%A1%A5%E6%8E%A5%E8%B4%9D%E5%A1%9E%E5%B0%94%E6%9B%B2%E7%BA%BF%E8%8A%82%E7%82%B9%E6%96%87%E6%9C%AC%E7%B2%97%E7%BB%86.png)
继续https://tex.stackexchange.com/a/581548,考虑以下代码:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections,angles,calc}
%%% Stolen from http://tex.stackexchange.com/a/581548
\makeatletter
\tikzset{bridge/.code args={#1 over #2}{%
\path[name path=tmp@bridge@path@B] #1;
\tikzset{name intersections={of=#2 and tmp@bridge@path@B,
by=tmp@i@0,total=\tmp@i@total}}
\ifnum\tmp@i@total=0
\typeout{These paths do not intersect. No bridge, sorry.}%
\else
\path[name path=tmp@bridge@path@C] (tmp@i@0)
circle[radius=\pgfkeysvalueof{/tikz/bridge radius}];
\tikzset{name intersections={of=tmp@bridge@path@B and tmp@bridge@path@C,
by={tmp@i@1,tmp@i@2},total=\tmp@i@total}}
\ifnum\tmp@i@total=2
\begin{scope}
\clip (tmp@i@0) circle[radius=\pgfkeysvalueof{/tikz/bridge radius}]
(current bounding box.south west) |-
(current bounding box.north east) |- cycle;
\draw[bridge-style] #1;
\end{scope}
\path let \p1=($(tmp@i@1)-(tmp@i@2)$),\n1={scalar(int(sign(\x1)))} in
\ifnum\n1=-1
pic [draw,line cap=round, angle radius=\pgfkeysvalueof{/tikz/bridge radius},
bridge-arc] {angle=tmp@i@2--tmp@i@0--tmp@i@1}
\else
pic [draw,line cap=round, angle radius=\pgfkeysvalueof{/tikz/bridge radius},
bridge-arc] {angle=tmp@i@1--tmp@i@0--tmp@i@2}
\fi;
\else
\typeout{Given the bridge radius \pgfkeysvalueof{/tikz/bridge radius},
the path is not suited to construct a nice bridge. No bridge, sorry.}%
\fi
\fi
},bridge radius/.initial=.5ex,
bridge style/.code={\tikzset{bridge-style/.style={#1}}},
bridge arc/.code={\tikzset{bridge-arc/.style={#1}}},
bridge style={},bridge arc={}}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{scope}
\draw[name path=A] (1,0) -- (1,1);
\tikzset{bridge={(3,.5) to node[above,pos=.33333333333333333333333]{\(\mathit{c3}\colon b\)} (0,.5)} over A}
\node at (2,.25) {\(\mathit{c3}\colon b\)};
\end{scope}
\end{tikzpicture}
\end{document}
将其输入pdflatex
并以 100% 的放大率打开结果,evince
我们会得到一张图像,其中使用桥接指令排版的文本比通常排版的相同文本更粗/更粗:
在qpdfview
100% 分辨率下,差异类似。在非常高的分辨率下,例如 1000%,我无法观察到 或 的厚度差异evince
。qpdfview
(边缘锐度可能有微小的、几乎难以辨认的差异。)为什么字体粗细的差异在低分辨率下如此明显,以及如何使使用桥接命令排版的文本粗细与平常相同?
答案1
在 PDF 的页面流中,字符串的上部实例在同一位置出现两次,这导致几乎每个 PDF 屏幕查看器都显示为更粗体。这是由于在低分辨率设备上渲染字体字形的贝塞尔曲线时存在不精确性。
为了修复此问题,可以执行以下操作:
路径的第一次出现仅用于计算交点。可以通过将此步骤隐藏在幻影框中来防止将路径插入页面流,幻影框仍会执行计算(但结果必须具有全局范围,因为在\phantom
其周围放置了一个组。):
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections,angles,calc}
%%% Stolen from http://tex.stackexchange.com/a/581548
\makeatletter
\tikzset{bridge/.code args={#1 over #2}{%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\phantom{%
\path[name path=tmp@bridge@path@B] #1;
\tikzset{name intersections={of=#2 and tmp@bridge@path@B,
by=tmp@i@0,total=\tmp@i@total}}%
\global\let\tmp@i@total\tmp@i@total%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifnum\tmp@i@total=0
\typeout{These paths do not intersect. No bridge, sorry.}%
\else
\path[name path=tmp@bridge@path@C] (tmp@i@0)
circle[radius=\pgfkeysvalueof{/tikz/bridge radius}];
\tikzset{name intersections={of=tmp@bridge@path@B and tmp@bridge@path@C,
by={tmp@i@1,tmp@i@2},total=\tmp@i@total}}
\ifnum\tmp@i@total=2
\begin{scope}
\clip (tmp@i@0) circle[radius=\pgfkeysvalueof{/tikz/bridge radius}]
(current bounding box.south west) |-
(current bounding box.north east) |- cycle;
\draw[bridge-style] #1;
\end{scope}
\path let \p1=($(tmp@i@1)-(tmp@i@2)$),\n1={scalar(int(sign(\x1)))} in
\ifnum\n1=-1
pic [draw,line cap=round, angle radius=\pgfkeysvalueof{/tikz/bridge radius},
bridge-arc] {angle=tmp@i@2--tmp@i@0--tmp@i@1}
\else
pic [draw,line cap=round, angle radius=\pgfkeysvalueof{/tikz/bridge radius},
bridge-arc] {angle=tmp@i@1--tmp@i@0--tmp@i@2}
\fi;
\else
\typeout{Given the bridge radius \pgfkeysvalueof{/tikz/bridge radius},
the path is not suited to construct a nice bridge. No bridge, sorry.}%
\fi
\fi
},bridge radius/.initial=.5ex,
bridge style/.code={\tikzset{bridge-style/.style={#1}}},
bridge arc/.code={\tikzset{bridge-arc/.style={#1}}},
bridge style={},bridge arc={}}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{scope}
\draw[name path=A] (1,0) -- (1,1);
\tikzset{bridge={(3,.5) to node[above,pos=.33333333333333333333333]{\(\mathit{c3}\colon b\)} (0,.5)} over A}
\node at (2,.25) {\(\mathit{c3}\colon b\)};
\end{scope}
\end{tikzpicture}
\end{document}