ConTeXt:文本背景的虚线框架

ConTeXt:文本背景的虚线框架

我想为某个textbackground部分设置自定义框架。我找到了如何使用overlay背景的代码framedtext,但它似乎不适用于textbackground。我是否遗漏了什么,或者这两个环境是否需要不同的方法?

带有简单虚线框的最小示例:

\startuseMPgraphic{dashed}
  path p; p := (0,0) -- 
               (OverlayWidth,0) -- 
               (OverlayWidth, OverlayHeight) -- 
               (0, OverlayHeight) -- (0,0);
  draw p withpen pencircle scaled 1.5pt dashed withdots;
\stopuseMPgraphic

\defineoverlay[Dashed][\useMPgraphic{dashed}]

\definetextbackground
  [withframe]
  [frame=on, location=paragraph]
\definetextbackground
  [withbackground]
  [frame=off, location=paragraph, background=Dashed]

\starttext

\startframedtext[frame=on]
This is framedtext with frame
\stopframedtext

\startwithframe
This is textbackground with frame
\stopwithframe

\startframedtext[frame=off, background=Dashed]
This is framedtext with background
\stopframedtext

\startwithbackground
This is textbackground with background
\stopwithbackground

\stoptext

答案1

“类似问题”列表中有一个链接,最终解决了我的问题,但我想我会保留这个问题,以防其他人从与我相同的角度来处理这个问题。

本质上,它似乎是textbackground使用mp而不是background,你不能使用相同类型的overlay与单个框架相同类型的代码。这个答案涉及在整个部分周围绘制一个框架。

最小工作示例(主要取自上面的链接):

% Dashed MPgraphic for framedtext
\startuseMPgraphic{dashedframe}
  begingroup;
  path p; p := (0,0) -- 
               (OverlayWidth,0) -- 
               (OverlayWidth, OverlayHeight) -- 
               (0, OverlayHeight) -- (0,0);
  draw p withpen pencircle scaled 1.5pt dashed withdots;
  endgroup;
\stopuseMPgraphic

\defineoverlay[DashedFrame][\useMPgraphic{dashedframe}]

% Dashed MPgraphic for textbackground 
\startuseMPgraphic{dashedbackground}
    begingroup;
        for i=1 upto nofmultipars :
            draw ( llcorner multipars[i]
                -- lrcorner multipars[i]
                -- urcorner multipars[i]
                -- ulcorner multipars[i]
                -- cycle )
            enlarged (EmWidth,EmWidth)
            withpen pencircle scaled 1.5pt dashed withdots;
        endfor ;
    endgroup;
\stopuseMPgraphic

\definetextbackground
  [framedbackground]
  [frame=off, mp=dashedbackground]

\starttext

\startframedtext[frame=off, background=DashedFrame]
This is framedtext with background
\stopframedtext

\startframedbackground
This is textbackground with mp 
\stopframedbackground

\stoptext

相关内容