1

Background

Looking to make speech bubbles autofit the text using ConTeXt LMTX.

Problem

The right padding on the framed text changes depending on whether the macro for \definefont is used. In the output (below), both frames should be fully justified. Switching the font breaks full justification.

Code

Sample code:

\definefont       [TextFontEmoji] [OpenSansEmoji]
\definefontfamily [TextFont] [rm] [LibreBaskerville] 
\setupbodyfont    [TextFont]

\starttext
  \startframedtext
    \TextFontEmoji
    \input ward
  \stopframedtext

  \startframedtext
    \input ward 
  \stopframedtext
\stoptext

The above code produces:

Text Frame Padding

Question

How do you switch the font while maintaining justification within a \framedtext environment?

1
  • Crossposted here.
    – mickep
    Apr 3, 2022 at 9:07

1 Answer 1

1

The OTF version of OpenSansEmoji cannot be justified with ConTeXt.

https://github.com/MorbZ/OpenSansEmoji

Completely remove the OTF version from the system and use the TTF version instead. This involves removing the luametatex-cache directory and rebuilding the font cache.

The following works as expected to produce left and right speech bubbles that include an emoji:

\definefont [TextFontEmoji] [OpenSansEmoji]

\startuseMPgraphic{TextBubble}{side}
  z1 = (0, 0) ;
  z2 = (OverlayWidth, 0) ;
  z3 = (OverlayWidth, OverlayHeight) ;
  z4 = (0, OverlayHeight) ;

  offset := 1 ;
  tail := 1 ;

  % Flip the tail's location and direction.
  if \MPvar{side} = 1:
    offset := 5 ;
    tail := -1 ;
  fi

  (offset/6)[x1,x2] = x8 + .25cm * tail = x7 + .25cm = x9 - .25cm ;
  y7 =  0cm ;
  y8 = -.5cm ;
  y9 =  0cm ;

  path p ;
  p = (z1--z7--z8--z9--z2--z3--z4--cycle) cornered .25cm ;
  draw p withpen pencircle scaled 0.75 ;

  setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\defineframedtext[TextBubbleFrame][
  style=TextFontEmoji,
  frame=off,
  width=.618\textwidth,
  autowidth=force,
  offset=.75em,
  after={\blank[2*big]},
]

% Receive text (left-facing).
\defineoverlay[TextBubbleRxOverlay][\useMPgraphic{TextBubble}{side=0}]
\defineframedtext[TextBubbleRxFrame][TextBubbleFrame][
  background=TextBubbleRxOverlay,
  location=left,
]

% Send text (right-facing).
\defineoverlay[TextBubbleTxOverlay][\useMPgraphic{TextBubble}{side=1}]
\defineframedtext[TextBubbleTxFrame][TextBubbleFrame][
  background=TextBubbleTxOverlay,
  location=right,
]

\definestartstop[bubblerx][
  before={\startnarrower\startTextBubbleRxFrame},
  after={\stopTextBubbleRxFrame\stopnarrower},
]

\definestartstop[bubbletx][
  before={\startnarrower\startTextBubbleTxFrame},
  after={\stopTextBubbleTxFrame\stopnarrower},
]

\starttext
  \startbubblerx
    Welcome to the future, human 👽!  \input zapf
  \stopbubblerx

  \startbubbletx
    Welcome to the future, human 👽!  \input zapf
  \stopbubbletx
\stoptext

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .