Update-1: This issue affects all fonts that assume glyph overlap. The 3 broad categories affected are: 1) All fonts for non-Latin scripts that inherently require glyph overlap, 2) Handwriting (cursive) fonts for Latin script, 3) Decoration fonts meant to build complex decorations (like decorative borders/frames) by repeating patterns of glyphs that partially overlap.
Update-2: This question has not been answered yet. After David Purton posted this ‘related answer’ below, the correct understanding is that tikz "transparency group" does apply grouped transparency to node text too. The mistake in my tikz code was that I invoked transparency grouping, but specified opacity at a different scope level. I have updated my original code in question, and tikz output looks good. This means the code needed for transparency grouping in text mode (outside tikz) can be either adapted from tikz codebase, or written by someone who understands
PDF XObjects
. It is fine even if transparency is applied only to latex's unbreakable boxes like packagetextpos
‘s environmenttexblock
orminipage
, or plain tex's boxes (vbox
andhbox
); that itself will be a big leap. Someone who understands macro\pdfxform
from section 8.8 of pdftex user manual might be able to help.
In some scripts it is almost impossible to have non-overlapping glyph components. Thats either because some complex glyphs are themselves composed of multiple -- potentially overlapping -- component glyphs, or by design adjacent glyphs need to overlap to form a word. Both are true for Devanagari, with the latter due to the fact that "overline" of glyphs in a word has to overlap to make it a word (its a script feature in addition to inter-word spacing). These overlaps are (rightly) not visible when text is set in a solid color, and are visible when it is set in a transparent one.
Setting fontspec
Opacity for such scripts produces ugly result (making it unusable), see for instance the following image that is Hindi word for male parent (पिताजी) set with Opacity. As you can see, Opacity setting results in darker spots at overlapping areas. This is because text is not grouped before applying transparency (Opacity setting applies transparency at individual glyph level). Tikz doesn't have this problem if one uses its implicit or explicit transparency grouping (tikz output not shown here, it can be seen by compiling code in this question). Below fontspec Opacity
output is the output from Adobe InDesign 2020 (I luckily still had access to trial version of InDesign) which looks great (no dark spots on overlap, and result looks uniform). I tested the output of text transparency grouping from both Tikz and Adobe InDesign, text is not converted to path upon grouping (text is copyable/searchable, which is great). From David Purton's analysis Tikz and Adobe InDesign produce similar PDF code.
LuaLaTeX with fontspec
and Opacity<1
output:
Adobe InDesign 2020 output:
An ideal solution will perform grouped transparency in text mode (its ok if it just works with HarfBuzz), like the way "transparency groups" work for tikz text and graphics. The text should still act like text in pdf, it should be searchable & copyable, and should not add any restrictions in text mode (such transparent text can span paragraphs, etc). If it makes it easier to implement, a solution could restrict itself to applying grouped transparency to package textpos
's environment textblock
or minipage
such that all objects within that environment will be part of transparency group (potentially with a parameter for blend mode, and potentially groups can be nested just like tikz transparency groups, and color commands \color/\textcolor
[though nesting would be an added bonus, not the most important]). As a side note, am not looking for a tikz solution (that acts similar to textpos or minipage with grouped transparency), though you are welcome to post a solution that does that for the broader community here (with first line explicitly stating in bold that "This is not a solution to this question, and is being posted here only to showcase what can be achieved with tikz.").[1]
[1] It might sound too strict, but IMO an incorrect answer that seems to partially solve the question might not invite further inquiry/drive towards a correct solution.
As a reference, the screenshot below from Section 17.3.1 of asppdf manual could lead us to a solution. It looks like the solution for the problem in this question would need to implement a transparency grouping like in the bottom-left figure in screenshot. The paragraphs above the four transparency grouping images explain things pretty well. The current transparency implementation functions like top-right image (transparency with no grouping, causing glyphs to composite with each other).
Here's the test code to regenerate the problem of dark areas at overlap. You might have to zoom-in to see the problem on screen, but it will be glaringly visible & distracting in a printed document. Lastly, this is not a font issue, and can be recreated with any existing Devanagari font.
% >> lualatex opacityoverlap.tex
\documentclass{article}
\usepackage{fontspec}
\usepackage{tikz}
\newfontfamily{\devanagarifamtext}{Noto Sans Devanagari}[Script=Devanagari, Scale=1, Renderer=HarfBuzz, Color=FF0000, Opacity=0.25]
\newfontfamily{\devanagarifamtikz}{Noto Sans Devanagari}[Script=Devanagari, Scale=1, Renderer=HarfBuzz, Color=FF0000]
\begin{document}
Text mode: {\devanagarifamtext एक गांव में पिताजी}
Tikz mode: \tikz[baseline,blend group=hue,opacity=0.25]{\node[inner sep=0pt,minimum width=0pt,outer sep=0pt,anchor=base] () {\devanagarifamtikz एक गांव में पिताजी};}
\end{document}
fontspec
optionOpacity
eventually writes/ca
entry to output PDF. Apparently inserting/BM
to set blend mode, either bytikz
or primitives is a workaround. Can you provide the output PDF from Adobe InDesign 2020, so that people here can dig into it and possibly find other workarounds?पिताजी
, 2) A semi-transparent circle behind text. It is uncompressed too (you can open it directly in a text editor). Link to PDF: drive.google.com/file/d/1hn-msdyAf605oEiDzUufNDuhOn_ta6Vh/…, Link to InDesign file: drive.google.com/file/d/1xUcHVyaSIhBrfMR746nvyXct2HvzNG_w/…. Maybe transparency groups are done withTransparency/Type/Group
in PDF (idk). Fyi, InDesign reverses order ofप
& ` ि` , so just use partताजी
as a pdf test search string.microtype
manual uses blend mode inside a graphic state inside a form object: all the right ingredients --\immediate\pdfobj{<</Type/ExtGState /CA 0.6 /ca 0.6 /BM/Normal >>}% \immediate\pdfxform attr {/Group <</Type/Group /S/Transparency /I true /CS/DeviceRGB >>} resources {/Properties <<\mtl@resources>> /ExtGState << /SXS \the\pdflastobj\space 0 R >> } \logobox