1

I'm working with a LaTeX template that uses Font Awesome 5 to render icons. Unfortunately, not all brand icons I would like exist in the Font Awesome set.

I have this PNG file:

kotlin.png

And I am rendering it with this code:

        \pointskill{\includegraphics[scale=0.015]{kotlin}}{Kotlin}{4}
        \pointskill{\faRust}{Rust}{1} % Including this for comparison

Which results in this:

Resulting Output

My goal is to change the colour of the icon in a generic way. That is, it should match the iconcolor defined here:

\colorlet{iconcolor}{maincolor!90}

Where maincolor is a variable that could be set to any color. By default it is:

\definecolor{cvblue}{HTML}{0E5484}
\colorlet{maincolor}{cvblue}

At the moment, the icon is rendered in the \pointskill command with \cvicon.

\newcommand{\cvicon}[1]{\makebox[0.8em]{\color{iconcolor} #1}}

I have tried to do this using decodearray, as per [this] (https://tex.stackexchange.com/a/150219/305810) answer, but I think I don't understand how to use it, as the image no longer renders when I use decodearray.

To summarise, how can I change the black colour in a PNG image, to match a variable colour?

Ogre
  • 113
  • 2
    If you would have them as vector graphic, changing the colour would be much easier. – samcarter_is_at_topanswers.xyz Oct 23 '23 at 20:00
  • @samcarter_is_at_topanswers.xyz, I do have them as SVG files. but I'm having trouble rendering them at all. I've posted a question about that issue: https://tex.stackexchange.com/questions/699323/struggling-to-get-includesvg-to-work – Ogre Oct 23 '23 at 21:14

1 Answers1

2

If you define your symbol (in pdfTeX) by

\newdimen\tenbp \tenbp=10bp
\def\mychar#1#2{% #1: scale #2: move up
   \leavevmode \hbox{%
      \pdfliteral{q #1 0 0 #1 0 #2 cm  0 0 m 10 0 l 5 5 l 10 10 l 0 10 l h f Q}%
      \kern#1\tenbp}}

then you can use \mychar{.75}{-1.2} in arbitrary color setting. You can tweak the two parametes: scale and vertical position. You don't need to load any external graphics file.

wipet
  • 74,238
  • Interesting. Is there an easy way to take an SVG file, and generate a \pdfliteral like this? There's a few icons I want to use, and they can be complicated, so I'd rather not do it manually if possible. – Ogre Oct 23 '23 at 21:18
  • Also, using this technique, how do I change the vertical positioning of the icon? It currently looks like the bottom of the icon is lined up with the bottom of the text, instead of being centered vertically. It may also be slightly too large. – Ogre Oct 23 '23 at 21:21
  • @Ogre see my edit, you can tweak the desired size and vertical position. To second question: you can load SVG to inkscape and save it as PostScript. Then you ca find the \pdfliteral content at the end of the *.ps file just after q 1 0 0 1 0 0 cm (it means open group and identical transformation matrix). – wipet Oct 24 '23 at 05:39
  • That seems to work for the Kotlin icon! I've managed to make postscript files for two more icons I want, but I'm having trouble understanding how to get the alignment and colour correct.

    I edited the typescript logo (https://www.typescriptlang.org/branding/) to get the text to cut out a transparent shape in the background, and the other icon I'm looking at is the graphql logo without text (https://graphql.org/brand/)

    – Ogre Oct 24 '23 at 06:21
  • pdfliteral is a very engine and output format dependant way to draw that and not something that would recommend for a user command. Use tikz or l3draw. – Ulrike Fischer Oct 24 '23 at 06:31
  • 1
    Engine dependency can be solved by simple one-line \def\pdfliteral{...} (in other engines than pdftex) and format dependency is irrelevant, because today only PDF format is used. On the other hand, tikz is a monster (tens of thousands of lines of code, more than 1000 pages of documentation). We needn't load it if it is not absolutely necessary. – wipet Oct 24 '23 at 12:39