I want to do something like https://tex.stackexchange.com/a/127902/176093
however the text I want to obfuscate is in a class and currently defined as \fontsize{1cm}{0cm}\selectfont my text
the class is written in LaTeX (may be LuaLaTex as wel??)
How should I do that?
example: file.tex
\documentclass[nosignatures,dvipsnames]{classfile.cls}
\usepackage{acronym}
\usepackage{luatexbase}
\usepackage{luaotfload}
\RequireLuaModule{obfuscate}
\def \packagecmd #1{\directlua {packagedata.#1}}
%% the obfuscate environment, mapping to Lua functions that enable and
%% disable tounicode obfuscation
\def \beginobfuscate {\packagecmd {obfuscate_begin ()}}
\def \endobfuscate {\packagecmd {obfuscate_end ()}}
\beginobfuscate
\font \italicfont = "file:Cantarell-Regular.otf:mode=base"
\endobfuscate
\begin{document}
\italicfont
hello
{\italicfont obfuscate please}
\showobfsc
\end{document}
classfile.cls
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{classfile}[26/03/2019 example class]
\renewcommand\normalsize{%
\@setfontsize\normalsize\@xpt\@xiipt
\abovedisplayskip 10\p@ \@plus2\p@ \@minus5\p@
\abovedisplayshortskip \z@ \@plus3\p@
\belowdisplayshortskip 6\p@ \@plus3\p@ \@minus3\p@
\belowdisplayskip \abovedisplayskip
\let\@listi\@listI}
\usepackage{acronym}
\usepackage{luatexbase}
\usepackage{luaotfload}
\RequireLuaModule{obfuscate}
\def \packagecmd #1{\directlua {packagedata.#1}}
%% the obfuscate environment, mapping to Lua functions that enable and
%% disable tounicode obfuscation
\def \beginobfuscate {\packagecmd {obfuscate_begin ()}}
\def \endobfuscate {\packagecmd {obfuscate_end ()}}
\beginobfuscate
\font \italicfont = "file:Cantarell-Regular.otf:mode=base"
\endobfuscate
\newcommand{\showobfsc}{
{\italicfont\fontsize{1cm}{1cm}\selectfont (this should be obfuscated)}\\[5cm]
}
\endinput
obfuscate.lua
packagedata = packagedata or { }
local mathrandom = math.random
local stringformat = string.format
--- this is the callback by means of which we will obfuscate
--- the tounicode values so they map to random characters of
--- the printable ascii range (between 0x21 / 33 and 0x7e / 126)
local obfuscate = function (tfmdata, _specification)
if not tfmdata or type (tfmdata) ~= "table" then
return
end
local characters = tfmdata.characters
if characters then
for codepoint, char in next, characters do
char.tounicode = stringformat ([[%0.4X]], mathrandom (0x21, 0x7e))
end
end
end
--- we also need some functions to toggle the callback activation so
--- we can obfuscate fonts selectively
local active = false
packagedata.obfuscate_begin = function ()
if not active then
luatexbase.add_to_callback ("luaotfload.patch_font", obfuscate,
"user.obfuscate_font", 1)
active = true
end
end
packagedata.obfuscate_end = function ()
if active then
luatexbase.remove_from_callback ("luaotfload.patch_font",
"user.obfuscate_font")
active = false
end
end
lualatex file.tex
ok it all wont work :(
\fontsize{1cm}{0cm}\selectfont my text
doesn't work) – hiddenhospitalresearch Apr 18 '19 at 22:22\fontsize{1cm}{0cm}\selectfont
doesn't obfuscate any text, it just sets large 1cm high text with inconsistent line spacing (as it will fail to achieve the specified 0pt spacing). The answer you link to is about preventing cutting and pasting text from the generated pdf, is that what you mean here or do you mean obscuring the text in the source view of the class file? as always it helps if you provide a complete small test file and say what you want it to do. – David Carlisle Apr 19 '19 at 7:37