Skip to content

Commit 5216d35

Browse files
chrjabssamcarter
andauthored
enable transparent background of beamercolorbox (#884)
implementation based on https://tex.stackexchange.com/questions/75839/transparency-of-beamercolorbox-and-opaqueness-of-its-text additional things that needed fixing: - implement transparent background for `rounded=false` - by default, don't change anything by not defining the `bgopacity` macros - more exact clipping of shadows when `bgopacity` is set Co-authored-by: samcarter <[email protected]>
1 parent ca548a1 commit 5216d35

5 files changed

+58
-9
lines changed

AUTHORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- Andreas Scherer <[email protected]> (documentation fixes)
3030
- Juergen Spitzmueller <[email protected]> (diabel auto-loading amssymb)
3131
- Gustav Tiger <[email protected]> (typos in manual)
32+
- Christoph Jabs <[email protected]> (transparency in beamercolorbox and beamerboxesrounded)
3233

3334
# Theme contributors
3435

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ a major and minor version only.
1111
### Added
1212

1313
- doc: added sentence about limitations of xelatex
14+
- added `bgopacity` option to `beamercolorbox` and `beamerboxesrounded` for transparent background drawing
1415

1516
### Changed
1617

base/beamerbaseboxes.sty

+31-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
\define@key{beamerboxes}{lower}{\def\bmb@lower{#1}}
2121
\define@key{beamerboxes}{width}{\edef\bmb@width{#1}}
2222
\define@key{beamerboxes}{shadow}[true]{\csname bmb@shadow#1\endcsname}
23+
\define@key{beamerboxes}{bgopacity}{\def\bmb@bgopacity{#1}}
2324

2425
\newif\ifbmb@shadow
2526
\newbox\bmb@box
@@ -80,6 +81,7 @@
8081
\else%
8182
\color{upper.bg}%
8283
\fi%
84+
\ifdefined\bmb@bgopacity\pgfsetfillopacity{\bmb@bgopacity}\fi
8385
\pgfpathqmoveto{-4bp}{-1bp}
8486
\pgfpathqcurveto{-4bp}{1.2bp}{-2.2bp}{3bp}{0bp}{3bp}
8587
\pgfpathlineto{\pgfpoint{\bmb@temp}{3bp}}
@@ -88,7 +90,17 @@
8890
{\pgfpoint{\bmb@dimb}{1.2bp}}%
8991
{\pgfpoint{\bmb@dimb}{-1bp}}%
9092
\bmb@dima=-\ht\bmb@box%
91-
\advance\bmb@dima by-2pt%
93+
\ifdefined\bmb@bgopacity%
94+
% Only with explicity specified opacity, make sure that there is no
95+
% overlap between top and bottom part of the box
96+
\ifdim\wd\bmb@box=0pt%
97+
\advance\bmb@dima by .5pt%
98+
\else%
99+
\advance\bmb@dima by -1.07pt%
100+
\fi%
101+
\else%
102+
\advance\bmb@dima by -2pt%
103+
\fi%
92104
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
93105
\pgfpathlineto{\pgfpoint{-4bp}{\bmb@dima}}
94106
\pgfusepath{fill}
@@ -105,13 +117,16 @@
105117
\advance\bmb@dima by8bp%
106118
\pgfpathrectangle{\pgfpoint{-4bp}{-1bp}}{\pgfpoint{\bmb@dima}{8bp}}
107119
\pgfusepath{clip}
120+
\ifdefined\bmb@bgopacity\pgfsetfillopacity{\bmb@bgopacity}\fi%
108121
{\pgftransformshift{\pgfpoint{-4bp}{0bp}}\pgftext[left,base]{\pgfuseshading{bmb@transition}}}%
109122
\end{pgfpicture}%
110123
}%
111124
\nointerlineskip%
112125
\vskip-0.5pt%
113126
\fi%
114-
\setbox\bmb@colorbox=\hbox{{\pgfpicturetrue\pgfsetcolor{lower.bg}}}%
127+
\setbox\bmb@colorbox=\hbox{{\pgfpicturetrue%
128+
\ifdefined\bmb@bgopacity\pgfsetfillopacity{\bmb@bgopacity}\fi%
129+
\pgfsetcolor{lower.bg}}}%
115130
\setbox\bmb@box=\hbox\bgroup\begin{minipage}[b]{\bmb@width}%
116131
\vskip2pt%
117132
\usebeamercolor[fg]{\bmb@lower}%
@@ -173,6 +188,16 @@
173188
\pgfsetcolor{beamer@safeblack}
174189
\pgfpathrectangle{\pgfpoint{4bp}{8.1bp}}{\pgfpoint{\bmb@boxwidth}{\bmb@boxheight-2bp}}
175190
\pgfusepath{fill}
191+
\ifdefined\bmb@bgopacity%
192+
% More precise clipping if bgopacity is specified
193+
\pgfpathqmoveto{-4bp}{8.2bp}
194+
\pgfpathqlineto{-4bp}{8bp}
195+
\pgfpathqcurveto{-4bp}{5.8bp}{-2.2bp}{4bp}{0bp}{4bp}
196+
\pgfpathlineto{\pgfpoint{\bmb@boxwidth}{4bp}}
197+
\pgfpathqcurveto{\dimexpr\bmb@boxwidth+2.2bp}{4bp}{\dimexpr\bmb@boxwidth+4bp}{5.8bp}{\dimexpr\bmb@boxwidth+4bp}{8bp}
198+
\pgfpathqlineto{\dimexpr\bmb@boxwidth+4bp}{8.2bp}
199+
\pgfusepath{fill}
200+
\fi%
176201
\end{pgfscope}
177202
\end{pgfpicture}%
178203
\hskip4bp%
@@ -204,6 +229,10 @@
204229
{\pgfpoint{\the\bmb@dimb}{1bp}}%
205230
{
206231
\bmb@dima=\ht\bmb@box%
232+
\ifdefined\bmb@bgopacity%
233+
% Remove overlap with bgtransparency specified
234+
\advance\bmb@dima by-.5pt%
235+
\fi%
207236
\pgfpathlineto{\pgfpoint{\bmb@dimb}{\bmb@dima}}
208237
\pgfpathlineto{\pgfpoint{-4bp}{\bmb@dima}}
209238
\pgfusepath{fill}

base/beamerbasecolor.sty

+21-7
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
\define@key{beamercolbox}{rounded}{\csname beamer@colbox@rounded#1\endcsname}
142142
\define@key{beamercolbox}{ignorebg}[true]{\csname beamer@colbox@ignorebg#1\endcsname}
143143
\define@key{beamercolbox}{vmode}[]{\def\beamer@vmode{}}
144+
\define@key{beamercolbox}{bgopacity}{\def\beamer@colbox@bgopacity{#1}}
144145

145146
\newif\ifbeamer@colbox@rounded
146147
\newif\ifbeamer@colbox@ignorebg
@@ -190,13 +191,24 @@
190191
\ifx\beamer@colbox@dp\@empty\else\dp\beamer@tempbox=\beamer@colbox@dp\fi%
191192
\ifbeamer@colbox@rounded%
192193
\if@tempswa%
193-
\begin{beamerboxesrounded}[%
194-
shadow=\beamer@colbox@shadow,%
195-
lower=\beamer@colbox@color,%
196-
upper=normal text,%
197-
width=\beamer@colbox@wd]{}%
198-
\box\beamer@tempbox%
199-
\end{beamerboxesrounded}%
194+
\ifdefined\beamer@colbox@bgopacity%
195+
\begin{beamerboxesrounded}[%
196+
shadow=\beamer@colbox@shadow,%
197+
lower=\beamer@colbox@color,%
198+
upper=normal text,%
199+
width=\beamer@colbox@wd,%
200+
bgopacity=\beamer@colbox@bgopacity]{}%
201+
\box\beamer@tempbox%
202+
\end{beamerboxesrounded}%
203+
\else%
204+
\begin{beamerboxesrounded}[%
205+
shadow=\beamer@colbox@shadow,%
206+
lower=\beamer@colbox@color,%
207+
upper=normal text,%
208+
width=\beamer@colbox@wd]{}%
209+
\box\beamer@tempbox%
210+
\end{beamerboxesrounded}%
211+
\fi%
200212
\else%
201213
\ifdim\wd\beamer@tempbox>\textwidth%
202214
\setbox\beamer@tempbox=\hbox to\textwidth{\hss\box\beamer@tempbox\hss}%
@@ -206,8 +218,10 @@
206218
\else%
207219
\if@tempswa\setbox\beamer@tempbox=\hbox{%
208220
\usebeamercolor{\beamer@colbox@color}%
221+
\ifdefined\beamer@colbox@bgopacity\pgfsetfillopacity{\beamer@colbox@bgopacity}\fi%
209222
\hskip-\beamer@colbox@colseps%
210223
\fboxsep=\z@\colorbox{bg}{%
224+
\pgfsetfillopacity{1}%
211225
\hskip\beamer@colbox@colseps%
212226
\box\beamer@tempbox%
213227
\hskip\beamer@colbox@colseps%

doc/beamerug-localstructure.tex

+4
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,8 @@ \subsection{Framed and Boxed Text}
842842
\declare{|ignorebg|} causes the background color of the \meta{beamer color} to be ignored, that is, to be treated as if it were set to ``transparent'' or ``empty.''
843843
\item
844844
\declare{|vmode|} causes \TeX\ to be in vertical mode when the box starts. Normally, \TeX\ will be in horizontal mode at the start of the box (a |\leavevmode| is inserted automatically at the beginning of the box unless this option is given). Only \TeX perts need this option, so, if you use it, you will probably know what you are doing anyway.
845+
\item
846+
\declare{|bgopacity|=\marg{opacity}} sets the opacity with which the background is drawn. To draw a box with 30\% transparent background, set |bgopacity=0.7|. Note that combining rounded corners and a transparent background can lead to fine gaps appearing in the box because the box is drawn in multiple segments. If |bgopacity| is not specified, |\pgfsetfillopacity| is never set so that the surrounding opacity setting is adopted.
845847
\end{itemize}
846848
\end{environment}
847849

@@ -856,6 +858,8 @@ \subsection{Framed and Boxed Text}
856858
\declare{|width=|\meta{dimension}} causes the width of the text inside the box to be the specified \meta{dimension}. By default, the |\textwidth| is used. Note that the box will protrude 4pt to the left and right.
857859
\item
858860
\declare{|shadow=|\meta{true or false}}. If set to |true|, a shadow will be drawn.
861+
\item
862+
\declare{|bgopacity|=\marg{opacity}} sets the opacity with which the background is drawn. To draw a box with 30\% transparent background, set |bgopacity=0.7|. Note that with a transparent background fine gaps can appear in the box because the box is drawn in multiple segments. If |bgopacity| is not specified, |\pgfsetfillopacity| is never set so that the surrounding opacity setting is adopted.
859863
\end{itemize}
860864
If no \meta{head} is given, the head part is completely suppressed.
861865
\example

0 commit comments

Comments
 (0)