如何为 D 触发器创建新的 pgf 形状?

如何为 D 触发器创建新的 pgf 形状?

我正在尝试根据\pgfdeclareshape命令创建一个新的形状(用于节点)。

我想定义的形状应该代表一个寄存器(又称 D 触发器),就像数字架构图中使用的寄存器一样。也就是说,一个盒子,在左下角附近稍高一点的地方添加了一个小的“>”符号(表示时钟输入)。我还想在边框上定义一些新的锚点。比如所谓的“D”输入和“Q”输出,一些“R”重置输入等,所有内容都可以选择显示或不显示(如果是,可能带有文本标签),具体取决于在节点定义时传递的参数。理想情况下,“>”符号的大小以及所有输入和输出的文本标签的字体大小将自动缩放到节点的大小。例如,这些大小将与节点的minimum width或成比例minimum height,“>”符号放置在主矩形高度的特定量上,例如 0.2 倍(20%)。

假设我希望功能齐全的新形状看起来像这样(除了不属于形状本身的四条小水平线):

在此处输入图片描述

我尝试模仿我在 TikZ/PGF 手册(3.0.1 版第 101 条)和网络上找到的示例,例如documentrectangle预定义形状继承的示例。唉,我无法让我的代码工作。当我尝试定义小“>”左下边缘的坐标时,例如使用\pgf@xd=\pgf@xa,我收到pdflatex错误。

有人知道如何创建这种形状吗?

提前致谢!

卡里姆

PS:下面是我的示例代码。我用注释指出了导致pdflatex崩溃的行。当我删除它时,我至少可以得到一个简单的……矩形。是的,我知道一切还远未结束 ;)

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

  \makeatletter
    \pgfdeclareshape{register}{
      \inheritsavedanchors[from=rectangle]
      \inheritanchorborder[from=rectangle]
      \inheritanchor[from=rectangle]{center}
      \inheritanchor[from=rectangle]{north}
      \inheritanchor[from=rectangle]{south}
      \inheritanchor[from=rectangle]{west}
      \inheritanchor[from=rectangle]{east}
      \backgroundpath{
        % store lower right in xa/ya and upper right in xb/yb
        \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
        \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
        % compute starting point of the '>'
        \pgf@xc=\pgf@xa
        \pgf@yc=\pgf@ya \advance\pgf@yc by -5pt % this should be a parameter
        % construct main path
        \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
        \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
        \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
        \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
        \pgfpathclose

        \pgf@xd=\pgf@xa
      }   
    }   

  \makeatother

  \begin{tikzpicture}
    \node[draw,shape=register,inner sep=2ex] (x) {D};
  \end{tikzpicture}

\end{document}

答案1

在提出这个问题的时候,没有\pgf@xdPGF\pgf@yd创建的有效 dimen 寄存器,这就是为什么

\pgf@xd=\pgf@xa

没有用。

自 2019 年起\pgf@xd\pgf@yd由 PGF 创建(仅\pgf@xd在一个地方使用)并且相关代码现在应该可以工作了。

相关内容